window.onload = function (){
    findByItem(1);
}

function findByItem(pageNO){
    axios.get("/goods/findByItem",{
        params:{
            pageNO,
            name:$("name").value,
            startDate:$("startDate").value,
            endDate:$("endDate").value
        }
    }).then(resp =>{
        var info = resp.data;
        let str = "";
        info.records.forEach(n =>{
            str += `<tr><td>${n.id}</td><td>${n.name}</td><td>${n.createDate}</td>
            <td>${n.price}</td><td><input type="button" value="删除" onclick="del(${n.id})">
            <input type="button" value="修改" onclick="location.href='/goods/update.html?id=${n.id}'"></td></tr>`;
        });
        $("data").innerHTML = str;

        var cutStr = "";
        for(let i=1;i<=info.pages;i++){
            cutStr += `<a style="margin-left: 10px" href="javascript:findByItem(${i})">${i}</a>`;
        }
        $("cutDiv").innerHTML = cutStr;
    });
}

function del(id){
    axios.get("/goods/del",{params: {id}}).then(resp => {
        if (resp.data == "ok") {
            findByItem(1);
        }
    });
}